/**
 * This is the player timer that keeps track of the game time and allows access
 * for other classes to get the current time remaing for player.
 * 
 * @author GT Five-O
 * @version v1.0b
 * 
 */

public class PlayerTimer implements java.io.Serializable {
    private Long roundTime;
    private Long roundLimit;
    private static int round;
    private Long init;

    /**
     * Sets the maximum amount of time for the player depending on the amount of
     * food the player has.
     * 
     * @param food
     * @param req
     * 
     * @return roundLimit
     */
    public Long getPlayerTime(int food, int req) {
        if (food >= req) {
            roundLimit = GameConstants.ROUND_LIMIT_FOOD_GREATER;
            return roundLimit;
        } else if (food == 0) {
            roundLimit = GameConstants.ROUND_LIMIT_FOOD_0;
            return roundLimit;
        } else {
            roundLimit = GameConstants.ROUND_LIMIT_FOOD_OTHER;
            return roundLimit;
        }
    }

    /**
     * Calculate the current time in milliseconds
     * 
     * @return fin
     */
    public Long calcTime() {
        Long fin = System.currentTimeMillis();
        return fin;
    }

    /**
     * Sets the current round time that will be used to determine whether or not
     * the player's time is up.
     * 
     * @param num
     */
    public void setRoundTime(Long num) {
        roundTime = num;
    }

    /**
     * Getter for RoundTime
     * 
     * @return roundTime
     */
    public Long getRoundTime() {
        return roundTime;
    }

    /**
     * Getter for roundLimit
     * 
     * @return roundLimit
     */
    public Long getRoundLimit() {
        return roundLimit;
    }

    /**
     * Stores an initial value to be used for player timer at the start of each
     * round.
     * 
     * @param num
     */
    public void storeInit(Long num) {
        init = num;
    }

    /**
     * Checks whether the round can keep continuing for the player
     * 
     * @return boolean
     */
    public boolean checkRound() {
        if (roundTime >= roundLimit) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * Sets the round number to determine the round limit
     * 
     * @param num
     */
    public void setRound(int num) {
        round = num;
    }

    /**
     * Returns the time that has elapsed since the initial value was recorded
     * 
     * @return calcTime() - init
     */
    public Long pubTime() {
        return (calcTime() - init);
    }
}
